<?php
/*
 * Copyright (C) 2006 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
/**
 * created Aug 31, 2007
 *
 * @author pablif@gmail.com
 */
 
require_once('../library/gb-authentication.php');
require_once('../library/gb-http.php');

if(!isset($_SESSION)) {
  session_start();
}

if(0) { ###### debug
  if(isset($_SESSION['gb_token'])) {
  	gb_revoke_session_token($_SESSION['gb_token']);
  	unset($_SESSION['gb_token']);
    echo 'blah';
  }
} ###### /debug

if(!array_key_exists('gb_token', $_SESSION)) {
  if(array_key_exists('token', $_GET)) {
    $gbhttp = new GoogleBaseHttpRequest('http://192.168.128.150:3128');
    $response = gb_get_session_token($_GET['token'], $gbhttp);
    if(!$response->hasErrors()) {
      $_SESSION['gb_token'] = $response->getParsedToken();
    }
    $gbhttp->close();
  } else {
    header("Location: " . gb_get_authentication_url());
  }
}
?>